package com.derbysoft.ota.application.translator.rq;

import com.derbysoft.modules.eip.translator.Translator;
import com.derbysoft.ota.interfaces.protocol._2009a.GuaranteeType.GuaranteeTypeEnum;
import com.derbysoft.remote.dswitch.hotel.constants.GuaranteeType;
import com.google.common.base.Preconditions;
import com.googlecode.functionalcollections.FunctionalIterable;
import com.googlecode.functionalcollections.FunctionalIterables;

import java.util.HashMap;
import java.util.Map;

public class GuaranteeTypeRQTranslator implements Translator<GuaranteeTypeEnum, GuaranteeType> {

	private Map<GuaranteeTypeEnum, GuaranteeType> supported() {
		Map<GuaranteeTypeEnum, GuaranteeType> map = new HashMap<GuaranteeTypeEnum, GuaranteeType>();
		map.put(GuaranteeTypeEnum.CC_DC_VOUCHER, GuaranteeType.CreditCard);
		map.put(GuaranteeTypeEnum.PRE_PAY, GuaranteeType.Prepay);
		return map;
	}

	public GuaranteeType translate(GuaranteeTypeEnum source) {
		return Preconditions.checkNotNull(supported().get(source),
				"Unsupported GuaranteeType [" + source + "], "
						+ "supported values are : "
						+ supportedValues());
	}

	private FunctionalIterable<GuaranteeTypeEnum> supportedValues() {
		return FunctionalIterables.<GuaranteeTypeEnum>create()
				.concat(GuaranteeTypeEnum.CC_DC_VOUCHER)
				.concat(GuaranteeTypeEnum.PRE_PAY);
	}

}
